package com.china08.yxyapi.api.home.kecheng.sync;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.YxyLessonsSynchroCatalog;
import com.china08.yxyapi.entity.db.res.YxyResPhase;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyLessonsSynchroCatalogRepository;
import com.china08.yxyapi.repository.db.YxyResPhaseRepository;

/**
 * 同步课程--列表页--学段
 * 
 * @author LiuWeidong
 *
 */
@CrossOrigin
@RestController
public class KechengSyncPhaceController extends YxyApiBaseController {

    @Autowired
    private YxyLessonsSynchroCatalogRepository yxyLessonsSynchroCatalogRepository;

    @Autowired
    private YxyResPhaseRepository yxyResPhaseRepository;

    @RequestMapping(value = "/api_yw/home/kecheng/sync/phace/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response) {
        List<RespModel> returnLst = new ArrayList<>();

        List<YxyLessonsSynchroCatalog> yxyResBookLst = yxyLessonsSynchroCatalogRepository.findBySatagIdAll();
        if (yxyResBookLst != null) {
            for (YxyLessonsSynchroCatalog yxyLessonsSynchroCatalog : yxyResBookLst) {
                RespModel model1 = new RespModel();
                String stageId = yxyLessonsSynchroCatalog.getStageId();

                YxyResPhase yxyResSubjects = yxyResPhaseRepository.findById(stageId);
                if (yxyResSubjects != null) {
                    model1.phaceId = yxyResSubjects.getId();
                    model1.phaceName = yxyResSubjects.getName();
                    returnLst.add(model1);
                }

            }
        }

        return returnLst;
    }

    /* 响应参数 */
    protected static class RespModel extends YxyApiRespModel {

        // 学段ID
        public String phaceId;
        // 学段
        public String phaceName;
    }
}
